#include<exeRecorder.h>
#include<pRecorder.h>
//executor端使用举例
void fun(ExeRecorder* t, std::string s){//多线程调用，注意临界资源互斥访问--可以加个互斥锁
    std::string cpu = "6", memory = "7";
    t->write(s, cpu, memory);
}
int main(){  
    pid_t pid;
    pid = fork();
    if(pid == -1)//错误创建
    {
        perror("fork error");
        _exit(1);
    }
    else if(pid == 0)//子进程
    {
        //cout<<"i am child,pid = "<<getpid()<<" my parent is:"<<getppid()<<endl;
        PRecorder* t = new PRecorder("/home/gk/Desktop/pe_test2/outputfile");
        for(int i = 0; i <1000; i++){
            t->write("a", "b", "c", "d", "e", "f", "g", "h");
        }
        t->writeEnd();
        delete t;
        return 0;
    }
    pid_t pid2;
    pid2 = fork();
    if(pid2 == -1)//错误创建
    {
        perror("fork error");
        _exit(1);
    }
    else if(pid2 == 0)//子进程
    {
        //cout<<"i am child,pid = "<<getpid()<<" my parent is:"<<getppid()<<endl;
        PRecorder* t = new PRecorder("/home/gk/Desktop/pe_test2/outputfile");
        for(int i = 0; i <1000; i++){
            t->write("a", "b", "c", "d", "e", "f", "g", "h");
        }
        return 0;
    }
    std::vector<int>v;
    v.push_back(pid);
    v.push_back(pid2);
    ExeRecorder* t = new ExeRecorder("/home/gk/Desktop/pe_test2/outputfile");
    t->setCallBack(std::bind(&fun, std::placeholders::_1,std::placeholders::_2));
    t->run(v);
    sleep(1000);
    std::cerr<<"suiwan";
    //t->stop();
    return 0;
}
/*
p端和executor端的文件地址必须相同地址
*/